package tw.fc.agui;

public abstract class GraphicObj extends GrObj {

   /**
    * 管理子物件的繪圖容器.
    */
   protected GraphicObjManager graphicObjM = null;

   /**
    * 畫布(為了使 GrObj能 invalidate).
    */
   protected GraphicPanel thePanel=null;  
   /**
    * 其父物件.
    */
   protected GraphicObj parentObj=null;   //: child-level Object用

   public ImuV2D getPosition() { 
      //: 可能不用. 若使用就須override. 例如 Eye.paintTo 會用到
      throw new RuntimeException("\n\nnot overrided in subclass of GrObj\n");
   }

   /**
    * 供程式師自定義繪製物件外觀.
    * @param g GrCanvas
    */
   public abstract void paintTo(GrCanvas g);

   public void setPanel(GraphicPanel p) {
      thePanel=p;
      this.parentObj = null;
      setPanelForChildren();
   }
   public void setParent(GraphicObj p) {  //: child-level Object ��
      this.thePanel = p.thePanel;
      parentObj=p;
   }

   /**
    * 重繪. (注意: 這會使整個畫面重新繪製)
    */
   public void invalidate() {  
      if(thePanel!=null) {  thePanel.invalidate();  }
   }

   /**
    * 使物件顯示在畫面的最頂層.
    */
   public void toTop() {  
      if(thePanel!=null) {  thePanel.GrObjM.toTop(this); }
      else {
         if (parentObj!=null) 
            throw new RuntimeException("not implement yet");
         else 
            throw new RuntimeException("illegal object");
      }
   }
   /**
    * 使物件顯示在畫面的最底層.
    */
   public void toBottom() {  
      if(thePanel!=null) {  thePanel.GrObjM.toBottom(this); }
      else {
         if (parentObj!=null) 
            throw new RuntimeException("not implement yet");
         else 
            throw new RuntimeException("illegal object");
      }
   }

   public void indexOf() {  
      if(thePanel!=null) {  thePanel.GrObjM.indexOf(this); }
      else if (parentObj!=null) {
         throw new RuntimeException("not implement yet");
      }
      else {
         throw new RuntimeException("unadded object");
      }
   }

   /**
    * 加入子繪圖物件.
    * @param ob 指定的繪圖物件.
    */
   public void addObj(GraphicObj ob) { 
      if(graphicObjM == null)
         graphicObjM = new GraphicObjManager(this);
      graphicObjM.add(ob); 
      ob.setParent(this);
   }

}

